﻿using SD.Infrastructure.EntityBase;
using System.Text;

namespace SD.ContentSystem.Domain.Entities
{
    /// <summary>
    /// 链接类别
    /// </summary>
    public class LinkCategory : AggregateRootEntity, ISortable
    {
        #region # 构造器

        #region 00.无参构造器
        /// <summary>
        /// 无参构造器
        /// </summary>
        protected LinkCategory() { }
        #endregion

        #region 01.创建链接类别构造器
        /// <summary>
        /// 创建链接类别构造器
        /// </summary>
        /// <param name="categoryNo">链接类别编号</param>
        /// <param name="categoryName">链接类别名称</param>
        /// <param name="sort">排序</param>
        public LinkCategory(string categoryNo, string categoryName, int sort)
            : this()
        {
            base.Number = categoryNo;
            base.Name = categoryName;
            this.Sort = sort;

            //初始化关键字
            this.InitKeywords();
        }
        #endregion

        #endregion

        #region # 属性

        #region 链接类别排序 —— int Sort
        /// <summary>
        /// 链接类别排序
        /// </summary>
        public int Sort { get; private set; }
        #endregion

        #endregion

        #region # 方法

        #region 修改链接类别信息 —— void UpdateInfo(string categoryName, int sort)
        /// <summary>
        /// 修改链接类别信息
        /// </summary>
        /// <param name="categoryName">链接类别名称</param>
        /// <param name="sort">排序</param>
        public void UpdateInfo(string categoryName, int sort)
        {
            base.Name = categoryName;
            this.Sort = sort;

            //初始化关键字
            this.InitKeywords();
        }
        #endregion

        #region 初始化关键字 —— void InitKeywords()
        /// <summary>
        /// 初始化关键字
        /// </summary>
        private void InitKeywords()
        {
            StringBuilder builder = new StringBuilder();
            builder.Append(base.Number);
            builder.Append(base.Name);

            base.SetKeywords(builder.ToString());
        }
        #endregion

        #endregion
    }
}
